<?php
require "./types.php";
require "./utility.php";

$id = $_GET["id"];
$conn = connect_mysql();

if ($id === null) {
    http_response_code(403);
} else {
    $query_str = "SELECT * FROM Book WHERE ID=$id;";
    $query = $conn->query($query_str);
    $book_data = $query->fetch_row();
    if (!$book_data) {
        http_response_code(404);
        exit();
    }
    $book = Book::fromArray($book_data);
    header("Content-Type: application/json");
    echo json_encode($book, JSON_UNESCAPED_UNICODE);
    $query->close();
    $conn->close();
}